<?php
class Products extends DataObject{
	static $db = array (
		"Name_en" => "Varchar(255)",
		"UrlApply" => "Varchar(255)",

		"IntroAPR" => "Varchar(255)",
		"BalanceTransfer" => "Varchar(255)",
		"RegularAPR" => "Varchar(255)",
		"AnnualFee" => "Varchar(255)",
		"IntroPeriod" => "Varchar(255)",
		"Brand" => "Varchar(255)",
		"CreditNeeded" => "Varchar(255)",
		"Summary_en" => "HTMLText",

		"IntroAPR" => "Varchar(255)",
		"BalanceTransfer" => "Varchar(255)",
		"RegularAPR" => "Varchar(255)",
		"AnnualFee" => "Varchar(255)",
		"CreditNeeded" => "Varchar(255)",

		"Content_en" => "HTMLText",
		"Status"=>"Boolean",
	);
	static $has_one = array (
		"Image"=>"Image",
		"Category"=>"Categories",
		"Type"=>"CardType",
	);
	static $searchable_fields = array (
		'TypeID'=> array('title'=>'Card Type'),
		'CategoryID'=> array('title'=>'Category Name'),
		'Name_en'=> array('title'=>'Product Name'),
		'Summary_en'=> array('title'=>'Summary'),
		'Status' => array('title'=>'Is show?'),
	);
	/**
	 * Overload so that the default sort.
	 */

	static $summary_fields = array (
		'Thumbnail' => 'Image',
		'Type.Name_en' => 'Card Type',
		'Category.Name_en' => 'Category Name',
		'Name_en' => 'Product Name',
		'StatusName'=>"Is show",
	);
	function getThumbnail()
	{
		if ($Image = $this->Image())
		{
			return $Image->CMSThumbnail();
		}
		else
		{
			return '(No Image)';
		}
	}
	function getStatusName()
	{
		if ($this->Status)
		{
			return 'Yes';
		}else	return 'No';
	}
	static $defaults = array(
		'Status' => 'True',
	);

	function getCMSFields($controller = null) {
		$fields = parent::getCMSFields();
		$drpCategoy=Lib::dropdown("Categories",null,"Name_en","CategoryID","Category Name",false);
		$drpType=Lib::dropdown("CardType",null,"Name_en","TypeID","Card Type",false);
		$TabVn= new Tab(_t('Career.TABCONTENTTITLEVN','Products'),
		$drpType,
		$drpCategoy,
		new TextField("Name_en", _t('Career.NAME_VI', 'Product name')),
		new TextField("UrlApply", _t('Career.NAME_VI', 'Apply Url')),
		new TextField("IntroAPR", _t('Career.NAME_VI', 'Intro APR')),
		new TextField("BalanceTransfer", _t('Career.NAME_VI', 'Balance Transfer')),
		new TextField("RegularAPR", _t('Career.NAME_VI', 'Regular APR')),
		new TextField("AnnualFee", _t('Career.NAME_VI', 'Annual Fee')),
		new TextField("CreditNeeded", _t('Career.NAME_VI', 'Credit Needed')),
		new TextField("IntroPeriod", _t('Career.NAME_VI', 'Intro Period')),
		new TextField("Brand", _t('Career.NAME_VI', 'Brand')),
		new HTMLEditorField("Summary_en", _t('Career.NAME_VI', 'Summary'),2,3),

		new TextField("IntroAPR", _t('Career.NAME_VI', 'Intro APR')),
		new TextField("BalanceTransfer", _t('Career.NAME_VI', 'Balance Transfer')),
		new TextField("RegularAPR", _t('Career.NAME_VI', 'Regular APR')),
		new TextField("AnnualFee", _t('Career.NAME_VI', 'Annual Fee')),
		new TextField("CreditNeeded", _t('Career.NAME_VI', 'Credit Needed')),
		new HTMLEditorField("Summary_en", _t('Career.NAME_VI', 'Summary'),2,3),

		new HTMLEditorField("Content_en", _t('Career.NAME_VI', 'Content'))
		);
		$TabImag= new Tab(_t('Career.TABCONTENTTITLEVN','Image'),
		new ImageField("Image",_t('Career.Status', 'Image')),
		new CheckboxField("Status",_t('Career.Status', 'Is show'))
		);
		if($this->ID){
			$fields = new FieldSet(new TabSet("Root",$TabVn,$TabImag));
		}else{
			$fields = new FieldSet(new TabSet("Root",$TabVn));
		}
		return $fields;
	}
	public function scaffoldSearchFields()
	{
		$fields = parent::scaffoldSearchFields();
		$drpType=Lib::dropdown("CardType",null,"Name_en","TypeID","Card Type",true);
		$drpCategoy=Lib::dropdown("Categories",null,"Name_en","CategoryID","Category Name",true);
		$drpStatus= Lib::dropdownYesNo('Status','Is show');
		$fields->replaceField('Status', $drpStatus);
		$fields->replaceField('CategoryID', $drpCategoy);
		$fields->replaceField('TypeID', $drpType);
		return $fields;
	}
	function getCMSValidator() {
		return new RequiredFields(array('Name_en'));
	}
	function canCreate() {return true;}
	function canEdit() {return true;}
	function canDelete() {return true;}
	function export() {return false;}

}